package com.ebuy.shopping.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ebuy.shopping.mapper.UserMapper;
import com.ebuy.shopping.model.User;

@Service
/**
 * 
 * @ClassName: UserService 
 * @Description: TODO 
 * @author wenzhao 
 * @date 2017年8月10日 上午10:25:53 
 *
 */
public class UserService implements IUserService
{
    @Autowired
    private UserMapper userMapper;

    @Override
    public User load(String UserId) throws Exception
    {
        return userMapper.selectByPrimaryKey(UserId);

    }

    @Override
    public List<User> getUsers() throws Exception
    {
        return userMapper.selectUsers();

    }

    @Override
    public int add(User user) throws Exception
    {
        return userMapper.insert(user);

    }

    @Override
    public int update(User user) throws Exception
    {
        return userMapper.updateByPrimaryKey(user);

    }

    @Override
    public User selectUserById(String userId) throws Exception
    {

        return userMapper.selectUserById(userId);
    }

    @Override
    public User login(String userName) throws Exception
    {
        return userMapper.selectByPrimaryKey(userName);
    }

    @Override
    public Boolean checkLogin(String userName, String password)
            throws Exception
    {

        Boolean flag = false;

        User user = userMapper.selectByPrimaryKey(userName);
        if (user != null)
        {
            String name = user.getUserName();
            String pasString = user.getPassword();
            if (userName.equals(name) && password.equals(pasString))
            {
                flag = true;
            }
        }

        return flag;

    }

    @Override
    public int deleteByPrimaryKey(String userId) throws Exception
    {

        return userMapper.deleteByPrimaryKey(userId);

    }
}
